package cn.scut.srp.controller.afterLogin.teacher;

import cn.scut.srp.model.BaseResponse;
import cn.scut.srp.model.ResponseCode;
import cn.scut.srp.model.entity.Message;
import cn.scut.srp.model.vo.CourseInfoVo;
import cn.scut.srp.model.vo.LoginVo;
import cn.scut.srp.model.vo.MessageVo;
import cn.scut.srp.service.CommonService;
import cn.scut.srp.service.TeacherService;
import cn.scut.srp.utils.JWTUtils;
import cn.scut.srp.utils.ResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "TeacherController",description = "教师角色使用的接口")
@RestController
@RequestMapping("/teacher/reserve")
@Slf4j
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private JWTUtils jwtUtils;
    //登录统一用一个吧
    @Operation(summary = "leaveMessage",description = "留言，可以进行设备报修以及非紧急问题的留言咨询。")
    @PostMapping("/leavemessage")
    public BaseResponse<ResponseCode> leaveMessage(@RequestHeader("Authorization") String token,String messageContent) {
        log.info(token);
        token=token.replaceFirst("Bearer ","");//swagger测试的时候老是在前面多出这个字段，很烦，额外处理一下
        log.info(token);
        String teacherAccount = (String)jwtUtils.analyzeToken(token).get("studentAccount");
        if(teacherAccount == null || messageContent == null||messageContent.equals("")){
            return ResponseUtil.noInfo("传入了空的留言!");
        }

        return teacherService.insertMeaasge(teacherAccount,messageContent);
    }
    //教师输入自己的班级以及课程信息
    @Operation(summary = "addCourse方法",description = "教师输入自己的班级以及课程信息")
    @PostMapping("/addcourse")
    public BaseResponse<ResponseCode> addCourse(@RequestHeader("Authorization") String token, CourseInfoVo courseInfoVo) {
        log.info(token);
        token=token.replaceFirst("Bearer ","");//swagger测试的时候老是在前面多出这个字段，很烦，额外处理一下
        String teacherAccount = (String)jwtUtils.analyzeToken(token).get("studentAccount");
        if(teacherAccount == null || courseInfoVo == null){
            return ResponseUtil.noInfo("课程信息或教师信息不能为空");
        }

        return teacherService.addCourse(token,courseInfoVo);
    }
}
